package com.javaEE.tes.controllers;

import com.javaEE.tes.entities.UserAccount;
import com.javaEE.tes.security.SecurityConfiguration;
import com.javaEE.tes.services.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
public class LoginController extends SecurityConfiguration {
//    @Autowired
//    UserAccountService userAccountService;
//    @Autowired
//    BCryptPasswordEncoder bCryptPasswordEncoder;
//    @GetMapping("/logins")
//    public String displayLogin(Model model) {
//        UserAccount userAccount = new UserAccount();
//        model.addAttribute("userAccount", userAccount);
//        return "security/login";
//    }
//    @PostMapping("/From")
//    public String LoginFrom( UserAccount userAccount) throws Exception{
//
////
////        userAccount.jdbcAuthentication().dataSource(dataSource)
////                .usersByUsernameQuery("SELECT username, password, enabled " + "FROM user_accounts WHERE username= ?")
////                .authoritiesByUsernameQuery("SELECT username, role " + "FROM user_accounts WHERE username = ?")
////                .passwordEncoder(bCryptPasswordEncoder);
////        登录逻辑函数
//
//        UserAccount userExistN =userAccountService.findUserName(userAccount.getUserName());
//        if(userExistN!=null){
//            String userExistP = userAccountService.findByPassByUserName(userAccount.getPassword());
//            if(userExistP.equals(userAccount.getPassword())){
//                return "redirect:/";
//            }else {
//                return "security/login";
//            }
//        }else {
//            return "security/login";
//        }
//    }
}


